package com.jumi.microservice.stock;

import com.jumi.microservice.domain.GoodsStockDO;
import com.jumi.microservice.domain.GoodsStockDTO;
import com.jumi.microservice.domain.GoodsWarehouseStockDO;
import com.jumi.microservice.mapper.GoodsStockMapper;
import com.jumi.microservice.mapper.GoodsWarehouseStockMapper;

import java.util.List;
import java.util.Map;

/**
 * @author Administrator
 */
public class SupplyStockUpdater extends AbstractSupplyStockUpdater {


    private Map<Long, GoodsStockDTO> goodsStockDtoMap;

    /**
     * 构造函数
     *
     * @param goodsStocks               商品库存DO对象
     * @param goodsWarehouseStocks      商品sku分仓库存DO对象
     * @param goodsStockMapper          商品库存管理模块的mapper组件
     * @param goodsWarehouseStockMapper 商品分仓库存管理模块的mapper组件
     */
    public SupplyStockUpdater(List<GoodsStockDO> goodsStocks,
                              List<GoodsWarehouseStockDO> goodsWarehouseStocks,
                              GoodsStockMapper goodsStockMapper,
                              GoodsWarehouseStockMapper goodsWarehouseStockMapper,
                              Map<Long, GoodsStockDTO> goodsStockDtoMap) {
        super(goodsStocks, goodsWarehouseStocks, goodsStockMapper, goodsWarehouseStockMapper);
        this.goodsStockDtoMap = goodsStockDtoMap;
    }

    @Override
    protected void updateSaleStockQuantity() throws Exception {
        for (GoodsStockDO goodsStock : goodsStocks) {
            GoodsStockDTO goodsStockDTO = goodsStockDtoMap.get(goodsStock.getGoodsSkuId());
            goodsStock.setGoodsSkuStorage(goodsStock.getGoodsSkuStorage() + goodsStockDTO.getGoodsSkuStorage());
        }
    }

    @Override
    protected void updatePreStockQuantity() throws Exception {
        for (GoodsStockDO goodsStock : goodsStocks) {
            GoodsStockDTO goodsStockDTO = goodsStockDtoMap.get(goodsStock.getGoodsSkuId());
            goodsStock.setPreStorage(goodsStock.getPreStorage() + goodsStockDTO.getPreStorage());
        }
    }

    @Override
    protected void updateWarehouseStockQuantity() throws Exception {

    }
}
